clear all
[vertex,face] = read_vtk('C:\Users\amir\Desktop\data\tumor.vtk');
vertex=vertex';
face=face';
x=vertex(:,1);
y=vertex(:,2);
z=vertex(:,3); 
trisurf(face, x , y ,z); hold on 
axis equal
%% This is my used grid for calculating intersected volumes
[X1 X2 X3]=meshgrid(linspace(min(vertex(:,1)),max(vertex(:,1)),20),linspace(min(vertex(:,2)),max(vertex(:,2)),20)...
,linspace(min(vertex(:,3)),max(vertex(:,3)),20));
X1 = reshape(X1,1,[])';
X2 = reshape(X2,1,[])';
X3 = reshape(X3,1,[])';
face3=delaunay([X1,X2,X3]);
trisurf(face3, X1 , X2 ,X3);
result = inhull([X1,X2,X3],vertex);
save('C:\Users\amir\Desktop\mycode\objmat.mat','X1','X2','X3','result');
%%
v=[(max(vertex(:,1))-min(vertex(:,1)))/2+min(vertex(:,1))...
(max(vertex(:,2))-min(vertex(:,2)))/2+min(vertex(:,2)) (max(vertex(:,3))-min(vertex(:,3)))/2+min(vertex(:,3))...
(max(vertex(:,1))-min(vertex(:,1)))/2+min(vertex(:,1))...
(max(vertex(:,2))-min(vertex(:,2)))/2+min(vertex(:,2)) (max(vertex(:,3))-min(vertex(:,3)))/2+min(vertex(:,3))...
45 20 10 50];
%%
xr=[5 5 10];
[x1,y1,z1]=ellipsoid(v(1),v(2),v(3),xr(1),xr(2),xr(3));
xEllipsoid1 = reshape(x1,1,[])';
yEllipsoid1 = reshape(y1,1,[])';
zEllipsoid1 = reshape(z1,1,[])';
teta1=deg2rad(v(7));
phi1=deg2rad(v(8));
xrotEllipsoid1 = [xEllipsoid1-v(1) yEllipsoid1-v(2) zEllipsoid1-v(3)]*[1 0 0;0 cos(teta1) -sin(teta1);0 sin(teta1) cos(teta1)];
yrotEllipsoid1 = xrotEllipsoid1*[cos(phi1) 0 sin(phi1);0 1 0;-sin(phi1) 0 cos(phi1)];
face1=delaunay(yrotEllipsoid1);
trisurf(face1,yrotEllipsoid1(:,1)+v(1),yrotEllipsoid1(:,2)+v(2),yrotEllipsoid1(:,3)+v(3)); hold on
axis equal
%%
[x2,y2,z2]=ellipsoid(v(4),v(5),v(6),xr(1),xr(2),xr(3));
teta2=deg2rad(v(9));
phi2=deg2rad(v(10));
xEllipsoid2 = reshape(x2,1,[])';
yEllipsoid2 = reshape(y2,1,[])';
zEllipsoid2 = reshape(z2,1,[])';
xrotEllipsoid2 = [xEllipsoid2-v(4) yEllipsoid2-v(5) zEllipsoid2-v(6)]*[1 0 0;0 cos(teta2) -sin(teta2);0 sin(teta2) cos(teta2)];
yrotEllipsoid2 = xrotEllipsoid2*[cos(phi2) 0 sin(phi2);0 1 0;-sin(phi2) 0 cos(phi2)];
face2=delaunay(yrotEllipsoid2);
trisurf(face2,yrotEllipsoid2(:,1)+v(4),yrotEllipsoid2(:,2)+v(5),yrotEllipsoid2(:,3)+v(6)); hold off
axis equal
starting:[[66 26 -1.9 61 22 -2.7 32.5 40.8 30.5 43.5]]
[66 26 -1.9 61 22 -2.7 32.5 40.8 30.5 43.5 66 26 -1.9 61 22]
low bound:[52 12 -7 52 12 -7 0 0 0 0]
[[52 12 -7 52 12 -7 0 0 0 0 52 12 -7 0 0]]
high bound: [73 36 10 73 36 10 180 180 180 180]
[73 36 10 73 36 10 180 180 180 180 73 36 10 180 180]